#include <cstdlib>
#include <cstdio>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <string>
#include <vector>
#include <cstring>
using namespace std;

typedef struct TCodeInfo {
	string code;
	string locality;
	double price;
	string priceStr;
	bool isIDD;
} TCodeInfo;
typedef struct TCallRecord {
	TCodeInfo dest;
	string number;
	string subNumber;
	double duration;
	double cost;
} TCallRecord;

typedef struct TTreeNode {
	int next[10];
	int infoIdx;
} TTreeNode;

typedef vector<TTreeNode> TTree;

vector<TCodeInfo> codeInfoList;
TTree codeInfoTree;
vector<TCallRecord> recordList;
int root = 0;

ostream& operator << (std::ostream &s, TCodeInfo x) {
	return cout << "code: " << x.code 
		<< "   loc: " << x.locality 
		<< "   price: " << x.price
		<< "   priceStr: " << x.priceStr;
}

ostream& operator << (std::ostream &s, TCallRecord x) {
	return cout << setw(16) << left << x.number
		<< setw(25) << left << x.dest.locality
		<< setw(10) << right << x.subNumber
		<< setw(5) << right << int(x.duration)
		<< setw(6) << right << x.dest.priceStr
		<< setw(7) << right << setprecision(2) << setiosflags(ios::fixed) << x.cost;
}

void readPart1(void) {
	string buf;
	while(true) {
		TCodeInfo info;
		cin >> info.code;
		if (info.code == "000000") return;
		scanf(" ");
		getline(cin, buf);
		info.locality = buf.substr(0, buf.find_last_of('$'));
		info.price = atof(buf.substr(buf.find_last_of('$')+1, buf.size()).c_str()) / 100;
		stringstream ss;
		ss << setprecision(2) << setiosflags(ios::fixed) << info.price;
		info.priceStr = ss.str();
		info.isIDD = (info.code.substr(0,2) == "00");
// 		cout << info << endl;
		codeInfoList.push_back(info);
	}
}

void readPart2(void) {
	while (true) {
		TCallRecord record;
		cin >> record.number;
		if (record.number == "#") return;
		cin >> record.duration;
		recordList.push_back(record);
	}
}

TTreeNode addNode(TTree& tree) {
	TTreeNode node;
	memset(node.next, 0, 10*sizeof(int));
	node.infoIdx = -1;
	tree.push_back(node);
	return node;
}

void insertCode(TTree& tree, int treeIdx, string x, int listIdx) {
	if (x.size() == 0) {
		tree[treeIdx].infoIdx = listIdx;
		return;
	}
	int d = x[0]-48;
	if (d<0 || d>9) return;
	if (tree[treeIdx].next[d] == 0) {
		addNode(tree);
		tree[treeIdx].next[d] = tree.size()-1;
	}
	insertCode(tree, tree[treeIdx].next[d], x.substr(1, x.size()-1), listIdx);
}

TTree buildTree(void) {
	TTree tree;
	tree.clear();
	addNode(tree);

	for (int i=0; i<codeInfoList.size(); ++i) {
		string code = codeInfoList[i].code;
		insertCode(tree, 0, code, i);
	}
	return tree;
}

TCallRecord genUnknown(TCallRecord x) {
	x.cost = -1;
	x.dest.locality = "Unknown";
	x.dest.priceStr = "";
	x.subNumber = "";
	return x;
}
TCallRecord genLocal(TCallRecord x) {
	x.cost = 0;
	x.dest.locality = "Local";
	x.dest.priceStr = "0.00";
	x.subNumber = x.number;
	return x;
}

int findInTree(TTree tree, int idx, string str) {
	if (str.size()==0) {
		return tree[idx].infoIdx;
	}

	int d = str[0]-48;

	if (tree[idx].next[d] > 0) {
		int infoIdx = findInTree(tree, tree[idx].next[d], str.substr(1, str.size()-1));
		if (infoIdx >= 0)
			return infoIdx;
		else
			return tree[idx].infoIdx;
	}
	return tree[idx].infoIdx;
}

TCallRecord parseRecord(TTree tree, TCallRecord x) {
	if (x.number[0] != '0') return genLocal(x);
	if (x.number.size() < 6)
		return genUnknown(x);
	for (int i=0; i<x.number.size(); ++i)
		if (x.number[i]<'0' || x.number[i]>'9')
			return genUnknown(x);
	int infoIdx;
	int prefixMinus = 4;
	while (prefixMinus<x.number.size()) {
		infoIdx = findInTree(tree, 0, x.number.substr(0, x.number.size()-prefixMinus));
		if (infoIdx >= 0) {
			x.dest = codeInfoList[infoIdx];
			x.subNumber = x.number.substr(x.dest.code.size(), 
				x.number.size()-x.dest.code.size());
			int subLen = x.subNumber.size();
			if (x.dest.isIDD) {
				if (subLen < 4 || subLen > 10) {
					++prefixMinus;
					continue;
				}
			}
			else {
				if (subLen < 4 || subLen > 7) {
					++prefixMinus;
					continue;
				}
			}
			break;
		}
		return genUnknown(x);
	}

	x.cost = x.duration*x.dest.price;
	return x;
}

int main(void)
{
// 	freopen("input.txt", "r", stdin);
	readPart1();
	codeInfoTree = buildTree();
	readPart2();
	
	for (int i=0 ;i<recordList.size(); ++i)
		cout << parseRecord(codeInfoTree, recordList[i]) << endl;

	return 0;
}